
function showTaskUpdateWindow(rowdata){
	
	 var projectdetailStore	=CRM.commons.createComboStore('projectdetailStore','projectTask/deatilsDropDownList','projects');
	 var statusDetailStore	=CRM.commons.createComboStore('statusDetailStore','projectTask/deatilsDropDownList','status');
	 var memberDetailsStore	=CRM.commons.createComboStore('memberDetailsStore','projectTask/deatilsDropDownList?operation=members&projectId='+rowdata.get('projectTaskId'));
	 var projectTaskStore	=CRM.commons.createStore('projectTaskStore',CRM.SPComp.projectTaskArray,'projectTask/tasksByProjectId');
	 var taskHomeGrid		=CRM.commons.createGrid('taskHomeGridId',projectTaskStore,CRM.SPComp.projectTaskColModel('taskHomeGridId'));
	 var taskCommentStore   =CRM.commons.createStore('taskCommentid', CRM.SPComp.commentTaskDataArray, 'projectTask/showTaskComments?taskId='+rowdata.get('id'));
	 
 
	 var  tpl = new Ext.XTemplate(
			 '<div style="background-color:#B3BCCC;"  style="margin-top:10px; height:50px" ><tpl for=".">',
		     '<p >&nbsp;', 
		     '<span><b>Assigned To&nbsp;:</b>&nbsp;</span><span ><b>{taskAssignedTo}<b></span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;',
		     '<span><b>Date&nbsp;:</b>&nbsp;</span><span ><b>{taskUpdatedDate}</b></span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;', 
		     '<span><b>Status&nbsp;:</b>&nbsp;</span><span><b>{taskStatus}<b></span>&nbsp;', 
		     '<br>', 
		   '<p >&nbsp;&nbsp;&nbsp;', 
		      '<div align="justify" style ="background-color:#B3BCCC;margin:10px 5px;width:100%;height:80px;top:100px;border-bottom:4px solid gray;overflow: scroll;"><span><b >Comment :</b>&nbsp;</span><b>{taskComment}<b></div>',
		      '</tpl></div>'); 
			 
	 var taskDescription={
				xtype	:'panel',
				id		:'taskDescription',
				layout	:'form',
				items	:[
				     	  {
				     		  xtype:'hidden',
				     		  id:'id',
				     		  fieldLebel: 'Task Id'	
				          },
					      {   
							xtype    	: 'combo',
	                        id       	: 'projectTaskName',
	                        fieldLabel	:'Projects',
	                        store		: projectdetailStore,
	                        displayField: 'name',
	                        valueField  : 'id',
	                        triggerAction: 'all',
	                        disable		: true,
	                        width		: 140,
	                        editable	: false,
	                        listeners 	: { select : function(){
											bindValue('projectTaskName','projectTaskId');
											}
										  }
	   				      },
					      {xtype:'hidden',id:'projectTaskId',value:'0'},
	   				      {
					    	  xtype		:'textfield',
					    	  fieldLabel:'TaskName',
					    	  width		: 335,
					    	  id		:'taskName'
					       },
					       {
					    	   xtype:'textarea',
					    	   fieldLabel:'Task Details',
					    	   height:70,
					    	   width:335,
					    	   id:'taskDetail'
					    	},
					        {
					    	   xtype     :'compositefield',
					    	   fieldLabel:'Status',
					    	   items:[ {
					    		        	  xtype		:'combo',
					    		        	  fieldLabel:'Status',
					    		        	  emptyText	:'SELECT',
					    		        	  id		:'taskStatus',
					    		        	  store		: statusDetailStore,
					                          displayField : 'name',
					                          valueField : 'id',
					                          triggerAction: 'all',
					                          width		: 120,
					                          editable	: false,
					                          listeners	:{select:function(){
							    	        	  			bindValue('taskStatus','taskStatusId');
					    	   							}
							    	    			}
					    		       },
					    		       {xtype:'hidden',id:'taskStatusId',value:'0'},
									   {  
					    		    	   xtype    :'displayfield', value : 'Assign To'
					    		       },
									   {
							    		   xtype    	: 'combo',
				                           id       	: 'assignTo',
				                           fieldLabel	:'Assign To',
				                           store		: memberDetailsStore,
				                           displayField : 'name',
				                           valueField  	: 'id',
				                           triggerAction: 'all',
				                           width		: 120,
				                           editable		: false,
				                           mode		    :'remote',
				                           listeners	:{select:function(){ 
					    		    	   						bindValue('assignTo','assignToId');
							    	        	  				}
					    		       				}
							    	   },
							           {xtype:'hidden',id:'assignToId',value:'0'}
					    	          ]
					       }
					   ],
			             tbar        : {
                           xtype       : 'toolbar',
                           items       : [
                                          	{
													xtype	: 'displayfield',
													id		: 'taskDetailDisplay',
													align   : 'left',
													width	: 415
													
												},
                                              {
												    xtype  : 'button',
												    text   : 'Add Comment', 
												    id     : 'addButton',
												    handler: function(){
													            var actionValue = Ext.getCmp('addButton').getText(); 
													            addUpdateTask(taskCommentStore);
													            
															}
											    },'-',
	    	                                    {
	                                    	      xtype   : 'button',
	                                    	      text    : 'Cancel',
	                                    	      id      :'cancelButton',
	                                    	      handler : closeCommentwin
	                                       }
	                                      ]
                         }
		};
	 
	 var taskUpdateRootPanel ={
             xtype       : 'fieldset',
             id          : 'taskUpdateRootPanel',
             height      :  210,
             width       :  600,
             frame       : false,
             items       : [taskDescription]
           };
	 
	 var taskCommentPanel = {
			  xtype		: 'fieldset',
			  id    	: 'taskCommentPanel',
			  title 	: 'Task Comments',
			  collapsible: false,
			  height 	:  370,
			  autoWidth :  true, 
			  autoScroll: false,
		      items		:  [{
					         	xtype     : 'dataview',
					         	tpl	      :tpl,
					         	store     :taskCommentStore,
					         	itemSelector: 'div.search-item'
			        	   }],
		     bbar		: new Ext.PagingToolbar({
		        	 			store		: taskCommentStore , 
					            pageSize	: 25,
					            displayInfo	: true,
					            displayMsg	: 'Topics {0} - {1} of {2}',
					            emptyMsg	: 'No topics to display'
		     			   })
		   };
	 
	 var combineTaskPanel = new Ext.FormPanel({
		  xtype	 : 'panel',
		  id     : 'combineTaskPanel',
		  height : 500,
		  width  : 620,
		  items	 : [taskDescription,taskCommentPanel]
	 });
	 disableTaskForm();
	 return combineTaskPanel;
	
 };
 
	 function taskCommentPupupWindow(rowdata)
	 {
		var combineTaskForm = showTaskUpdateWindow(rowdata);
		
	    taskUpdatewin = new Ext.Window({
 		   id          : 'taskUpdatewin',
 		   title       : 'Updated Task',
 		   width       : 630,
 		   height      : 580,
 		   layout      : 'fit',
 		   border      : false,
 		   plain       : false,
 		   closable    : true,
 		   collapsible : true,
 		   animCollapse: false,
 		   draggable   : false,
 		   maximizable : true,
 		   onEsc	   : true,
 		   model	   : true,  
 		   items       : [combineTaskForm]
         });
	    combineTaskForm.getForm().loadRecord(rowdata);
	    //displayTaskName(rowdata);
	    taskUpdatewin.show(this);
	   
	    return taskUpdatewin; 
	
 };
 
 function addUpdateTask(taskCStore){
     
	   var taskId = Ext.getCmp('id').getValue(); 
	   var formPanel = Ext.getCmp('combineTaskPanel');
	    var values = formPanel.getForm().getValues();
	   var encoded = Ext.encode(values);
	   Ext.Ajax.request({
	        		   url		: 'projectTask/saveTaskComment?taskId='+taskId,
	        		   method	: 'POST',
	      	            success : function(result, request) {  
	  	        		         alert("Comment Updated Successfully.");
	  	        		         
	  	        		         taskCStore.reload();
	  	        		         var taskHomeGrid=Ext.getCmp('taskHomeGrid');
	  	        		         taskHomeGrid.store.reload();
	  	        		      },
	      	   failure: function() {
	  	        		    	  alert ("Failure"); 
	      	   					 },
	      	   jsonData: encoded  
	      	}); 
	  };

 
   var taskIdsArray = ["projectTaskName","taskName"];
 
    function disableTaskForm(){
    	var taskForm = Ext.getCmp('combineTaskPanel'); 
	    doFormReadOnly(taskForm, taskIdsArray, true);
		
	};
	
	
	function displayTaskName(rowData){
	 		var taskNameValue  = rowData.get('taskName');
	 		Ext.getCmp('taskNameDisplay').setValue("<b>&nbsp" + taskNameValue + "</b>"); 
	 	};

	function closeCommentwin(){
		taskUpdatewin.close();
	}